package com.acwing.lc.part1;

import java.util.*;

/**
 * @author rkc
 * @date 2022/9/15 10:37
 */
public class LC49字母异位词分组 {

    public List<List<String>> groupAnagrams(String[] strs) {
        Map<String, List<String>> map = new HashMap<>();
        for (String str : strs) {
            char[] arr = str.toCharArray();
            Arrays.sort(arr);
            String key = new String(arr);
            List<String> vals = map.getOrDefault(key, new ArrayList<>());
            vals.add(str);
            map.put(key, vals);
        }
        return new ArrayList<>(map.values());
    }
}
